<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

if($_GET['id']) $id=$_GET['id'];
else $id=$_POST['id'];

if(!$id)
{
        $requete = "select * from genres";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                echo "<CENTER><H3>";
		echo _("Modifier un genre de livre");
		echo "</H3>";
                echo "<TABLE><TR><th>";
		echo _("Genre");
		echo "</th><th>";
		echo _("Action");
		echo "</th>";
        
                while ($row = biblio_db_fetch_array($resultat)) 
	        {      
                        $genre_id = $row['id'];           
                        $genre_nom =  $row['genre']; 
                        echo "<TR><TD>$genre_nom</TD><TD><A href=\"admin.php?action=mod&type=genre&id=$genre_id\"><IMG SRC=\"images/wh_r_arr.gif\" ALT=\"";
			echo _("changer");
			echo "\" border=0 align=right></A></TD>";            
                }
                echo "</TABLE></CENTER>";
        }
}
else
{
    if ($_POST['sw']!=1)
    {
 
       $requete = "select * from genres where id=$id";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                while ($row = biblio_db_fetch_array($resultat)) 
	        {      
                        $genre_id = $row['id'];           
                        $genre_nom =  $row['genre'];      
                }
         }
        ?>
        <CENTER><H3>
	<?php echo _("Modifier le genre"); ?>
	</H3>
        <I><?php echo _("Tous les livres ayant ce genre seront modifi&eacute;s en cons&eacute;quence..."); ?></I><BR><BR>
        <FORM action=admin.php METHOD=POST>
        <TABLE BORDER=0>
        <TR>
        <TD>
	<?php echo _("Genre"); ?>
	:</TD><TD><INPUT TYPE="text" NAME="genre" size = 20 value="<?php echo $genre_nom; ?>"></TD>
        <TR>
        </TABLE><BR>
        <INPUT TYPE="hidden" NAME="user" value="<?php echo $user; ?>">
        <INPUT TYPE="hidden" NAME="action" value="<?php echo $action; ?>">
        <INPUT TYPE="hidden" NAME="type" value="<?php echo $type; ?>">
        <INPUT TYPE="hidden" NAME="sw" value="1">
        <INPUT TYPE="hidden" NAME="id" value="<?php echo $id; ?>">        
        <input type="Submit" value="
	<?php echo _("Enregistrer"); ?>
	">
        </FORM>
        </CENTER>
        <?php
    }   
    else
    {
      $requete = "update genres set genre='". $_POST['genre'] ."' where id=$id";
      if(!($resultat = biblio_db_query($requete)))
      { echo _("PROBLEME : ") .biblio_db_error(); exit;}  
      put_log(3,$requete,$user);
      echo "<CENTER><BR>";
      echo _("Le genre a &eacute;t&eacute; modifi&eacute; comme");
      echo ": <b>${_POST['genre']}</b>.<br></center>";
    } 
}
?>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
